#include "gdl703t.h"
#include "pipe_communicate.h"
#include "mqueue_communicate.h"

//设备初始化
int gdl703t_init(){
    int nResult=0;//sdk执行返回结果
	time_t now;
    int tidx;//设备ID

    is_connect=0;

    memset(g_TermList, 0, sizeof(g_TermList));//清空设备列表
	memset(g_TermState, 0, sizeof(g_TermState));//清空状态列表
	g_nTermCnt = 0;

    //注册SDK
    nResult = TSDK_Init(OnTzlSdkCallback, TRUE, 0x12345678);
    if(nResult == CERR_SUCCESS)printf("SDK 初始化成功！\n\r");
    else printf("SDK 初始化失败！错误代码:%d \n\r", nResult);

    //等待连接回应
    while (!is_connect){printf(">>>>>\n");sleep(1);};


	printf("/*******************************************/\n\r");

    return tidx;
}
//开始获取音频数据
int gdl703t_start(char routes){
    int nResult;

    if(devID >= g_nTermCnt)
    {
        printf("!!!! DevIdx:%d not register !!!! \n", devID);
        printf("\n");
        exit(2);
    }
    else if(g_TermState[devID].eState == TSDK_DEV_STATE_OFFLINE)
    {
        printf("!!!! DevIdx:%d is offline !!!! \n", devID);
        printf("\n");
        exit(2);
    }
    //请求打开实时PCM
    nResult = TSDK_Req_OpenTermPcm(g_TermList[devID].dwTermID);
    if(nResult != CERR_SUCCESS)
    {
        printf("!!!! 错误：请求打开实时PCM失败！错误代码:%d !!!!\n", nResult);
        exit(2);
    }
    g_nRecordTermIdx = devID;
    /******************************************************************/

    //开启分析音量
    nResult = TSDK_Req_DbAnalyze(g_TermList[devID].dwTermID,1);
	if(nResult != CERR_SUCCESS)
    {
        printf("!!!! 错误：请求分析音量失败！错误代码:%d !!!!\n", nResult);
        exit(2);
    }

	/******************************************************************/
	//保存R通道音频
	// g_pPcmFileR = fopen("./R16k_16b.pcm", "wb");//打开文件

	//初始化管道
#if COMMUNICATION_MODE == MQUEUE
	mqueue_init(MQUEUE_R_PATH,'r');
#elif COMMUNICATION_MODE == PIPE

	switch (routes)
	{
	case 'r':
		pipo_R_data_fd = pipe_init(PIPE_R_PATH);
		break;
	case 'l':
		pipo_L_data_fd = pipe_init(PIPE_L_PATH);
		break;
	case 'a':
		pipo_R_data_fd = pipe_init(PIPE_R_PATH);
		pipo_L_data_fd = pipe_init(PIPE_L_PATH);
		break;
	default:
		printf("No channel selected ! \n\r");
		exit(1);
		break;
	}
#else

#endif
    return 0;
}
//关闭设备数据传输
int gdl703t_stop(int devid){
	int nResult;
	devid = devID;

	nResult = TSDK_Req_CloseTermPcm(g_TermList[devid].dwTermID);
	if(nResult != CERR_SUCCESS)
    {
        printf("!!!! 错误：关闭终端实时PCM音频失败！错误代码:%d !!!!\n", nResult);
        exit(2);
    }

	// fclose(g_pPcmFileR);

	return 0;
}
//遗弃
int getDB(char *r_l){

	char a = &r_l;

	printf("<<< in_char:%c\n\r",a);
	switch (a)
	{
	case 'r':
		return r_db;
		break;
	case 'l':
		return l_db;
		break;
	default:
		return -1;
		break;
	}
}

int getDB_char(char r_l){

	// printf("<<< in_char:%c\n\r",r_l);
	switch (r_l)
	{
	case 'r':
		return r_db;
		break;
	case 'l':
		return l_db;
		break;
	default:
		return -1;
		break;
	}
}
//获取连接状态
int get_is_connect(){

	return is_connect;
}

/***********************************************************/

static LPCSTR GetStateText(enSdkDevState eState)
{
	switch(eState)
	{
	case TSDK_DEV_STATE_OFFLINE:
		return "不在线";
	case TSDK_DEV_STATE_ONLINE:
		return "在线";
	case TSDK_DEV_STATE_PLAYING:
		return "播放音乐";
	case TSDK_DEV_STATE_TALKING:
		return "通话中";
	case TSDK_DEV_STATE_TALK_PLAY:
		return "通话中并播放音乐";
	}

	return "未知状态";
}
static LPCSTR GetTermType(enSdkDevType eTermType)
{
	switch(eTermType)
	{
	case TSDK_DEV_TYPE_TALK:
		return "[对讲广播终端]";
	case TSDK_DEV_TYPE_BROAD:
		return "[广播终端]";
	case TSDK_DEV_TYPE_MP3:
		return "[网络拾音器]";
	}

	return "[未知类型终端]";
}
static void StopRecord(int tidx)
{
	if(!g_TermState[tidx].pMp3File1 && !g_TermState[tidx].pMp3File2)
		return;

	char strText[256];
	if(g_TermState[tidx].eState != TSDK_DEV_STATE_OFFLINE)
	{
		int nResult = TSDK_Req_CloseTermAudVid(g_TermList[tidx].dwTermID);
		if(nResult != CERR_SUCCESS)
		{
			sprintf(strText, "!!!! 错误：关闭网络拾音器MP3流失败！错误代码:%d", nResult);
			printf("%s \n", strText);
		}
		THREAD_SLEEP(300);
	}

	if(g_TermState[tidx].pMp3File1)
	{
		fclose(g_TermState[tidx].pMp3File1);
		g_TermState[tidx].pMp3File1 = NULL;
		sprintf(strText, "xx结束录音, 设备:[%s] - 通道1", g_TermList[tidx].TermName);
		printf("%s \n", strText);
	}

	if(g_TermState[tidx].pMp3File2)
	{
		fclose(g_TermState[tidx].pMp3File2);
		g_TermState[tidx].pMp3File2 = NULL;
		sprintf(strText, "xx结束录音, 设备:[%s] - 通道2", g_TermList[tidx].TermName);
		printf("%s \n", strText);
	}
}
static void StartRecord(int tidx)
{
	if(g_TermState[tidx].eState == TSDK_DEV_STATE_OFFLINE)
		return;

	if(g_TermState[tidx].pMp3File1 || g_TermState[tidx].pMp3File2)
		return;

	struct tm * ptm_now;
    time_t now;

	now = time(&now);
	g_TermState[tidx].dwStartTime = now;
    ptm_now = localtime(&now); //gmtime(&now);

	char DateDir[128];
	char DevDir[128];
	char FilePath[256];
	char strText[256];//输出缓存
	
	sprintf(DateDir, "%s%d-%02d-%02d", "./", ptm_now->tm_year+1900/*2000*/, ptm_now->tm_mon+1, ptm_now->tm_mday);
	mkdir(DateDir, 0755);

	sprintf(DevDir, "%s/%s", DateDir, g_TermList[tidx].TermName);
	mkdir(DevDir, 0755);

	// sprintf(FilePath, "%s/%02d%02d%02d-1.mp3", DevDir, ptm_now->tm_hour, ptm_now->tm_min, ptm_now->tm_sec);
	// g_TermState[tidx].pMp3File1 = fopen(FilePath, "wb");
	// if(g_TermState[tidx].pMp3File1)
	// 	sprintf(strText, "==开始录音: %s", FilePath);
	// else
	// 	sprintf(strText, "!!!! 错误：创建MP3文件失败 !!!! %s", FilePath);
	// printf("%s \n", strText);

	sprintf(FilePath, "%s/%02d%02d%02d-2.mp3", DevDir, ptm_now->tm_hour, ptm_now->tm_min, ptm_now->tm_sec);
	g_TermState[tidx].pMp3File2 = fopen(FilePath, "wb");
	if(g_TermState[tidx].pMp3File2)
		sprintf(strText, "==开始录音: %s", FilePath);
	else
		sprintf(strText, "!!!! 错误：创建MP3文件失败 !!!! %s", FilePath);
	printf("%s \n", strText);

	int nResult = TSDK_Req_OpenTermAudVid(g_TermList[tidx].dwTermID);//打开实时音频
	if(nResult != CERR_SUCCESS)
	{
		sprintf(strText, "!!!! 错误：请求网络拾音器MP3流失败！错误代码:%d !!!!", nResult);
		printf("%s \n", strText);
	}

	return;
}

int CALLBACK OnTzlSdkCallback(enSdkCbType eCbType, LPVOID pParam, DWORD dwSize, int usr_data)
{
	int ret;

	switch(eCbType)
	{
        //终端请求注册通知
		case CB_Event_TermRegister:
		{
			ASSERT(dwSize == sizeof(TSdkEventTermRegister));
			TSdkEventTermRegister * pEventTermRegister = (TSdkEventTermRegister*)pParam;
			LPBYTE p = pEventTermRegister->TermMac;
			char strText[256];
			sprintf(strText, "===> %s 请求注册：终端ID:0x%X , MAC地址:%02X-%02X-%02X-%02X-%02X-%02X , IP地址:%s , 名称:%s",
				GetTermType(pEventTermRegister->eTermType), pEventTermRegister->dwTermID, p[0],p[1],p[2],p[3],p[4],p[5], pEventTermRegister->TermIp, pEventTermRegister->TermName);
			printf("%s \n", strText);
			
			return CERR_SUCCESS; // 返回 0 代表注册成功，否则代表注册失败 !!!
		}
        //终端请求连接通知
		case CB_Event_TermConnect:
		{
			ASSERT(dwSize == sizeof(TSdkEventTermConnect));
			TSdkEventTermConnect * pEventTermConnect = (TSdkEventTermConnect*)pParam;
			LPBYTE p = pEventTermConnect->TermMac;
			printf(">>>>> %s 请求连接：终端ID:0x%X , %s视频 , MAC地址:%02X-%02X-%02X-%02X-%02X-%02X , IP地址:%s , 名称:%s\n",
				GetTermType(pEventTermConnect->eTermType), pEventTermConnect->dwTermID, (pEventTermConnect->bHasVideo ? "有" : "无"),
				p[0],p[1],p[2],p[3],p[4],p[5], pEventTermConnect->TermIp, pEventTermConnect->TermName);

			int i;
			for(i=0; i<g_nTermCnt; i++)//获取到设备ID
			{
				if( (g_TermList[i].dwTermID == pEventTermConnect->dwTermID) &&
					memcmp(g_TermList[i].TermMac, pEventTermConnect->TermMac, 6) == 0)
				{
					break;
				}
			}

			if(i >= g_nTermCnt)
			{
				g_TermList[i].eTermType = pEventTermConnect->eTermType;
				g_TermList[i].dwTermID = pEventTermConnect->dwTermID;
				memcpy(g_TermList[i].TermMac, pEventTermConnect->TermMac, 6);
				strcpy(g_TermList[i].TermIp, pEventTermConnect->TermIp);
				strcpy(g_TermList[i].TermName, pEventTermConnect->TermName);

				g_nTermCnt += 1;
			}

			BOOL bChangeIp = strcmp(g_TermList[i].TermIp, pEventTermConnect->TermIp);
			if(bChangeIp)
				strcpy(g_TermList[i].TermIp, pEventTermConnect->TermIp);

			BOOL bChangeName = strcmp(g_TermList[i].TermName, pEventTermConnect->TermName);
			if(bChangeName)
				strcpy(g_TermList[i].TermName, pEventTermConnect->TermName);

			g_TermList[i].eTermType = pEventTermConnect->eTermType;
			g_TermState[i].bTalkbackEnable = pEventTermConnect->bTalkbackEnable;
			g_TermState[i].eState = TSDK_DEV_STATE_ONLINE;

            

			return CERR_SUCCESS; // 返回 0 代表允许连接，否则代表不允许 !!!
		}
        //终端断开通知
		case CB_Event_TermCnnLost:
		{
			ASSERT(dwSize == sizeof(TSdkEventTermCnnLost));
			TSdkEventTermCnnLost * pEventTermCnnLost = (TSdkEventTermCnnLost*)pParam;
			char strText[256];
			sprintf(strText, "xxx 终端断开连接：终端ID:0x%X", pEventTermCnnLost->dwTermID);
			printf("%s \n", strText);

			//断开连接了
			is_connect=0;	

			int i;
			for(i=0; i<g_nTermCnt; i++)
			{
				if(g_TermList[i].dwTermID == pEventTermCnnLost->dwTermID)
				{
					g_TermState[i].eState = TSDK_DEV_STATE_OFFLINE;

					StopRecord(i);

					break;
				}
			}
            is_connect=0;
//			g_pMainWnd->UpdateTermListUI();

			break;
		}
		//应答打开终端音频视频
		case CB_Asw_OpenTermAudVid:
		{
			ASSERT(dwSize == sizeof(TSdkAswOpenTermAudVid));
			TSdkAswOpenTermAudVid * pAswOpenTermAudVid = (TSdkAswOpenTermAudVid*)pParam;
			char strText[256];
			if(pAswOpenTermAudVid->nResult == CERR_SUCCESS)
				sprintf(strText, "打开终端音频成功！终端ID:0x%X ", pAswOpenTermAudVid->dwTermID);
			else
				sprintf(strText, "打开终端音频失败！终端ID:0x%X ，错误代码:%d", pAswOpenTermAudVid->dwTermID, pAswOpenTermAudVid->nResult);
			printf("%s \n", strText);
			break;
		}
        //应答关闭终端音频视频
		case CB_Asw_CloseTermAudVid:
		{
			ASSERT(dwSize == sizeof(TSdkAswCloseTermAudVid));
			TSdkAswCloseTermAudVid * pAswCloseTermAudVid = (TSdkAswCloseTermAudVid*)pParam;
			char strText[256];
			if(pAswCloseTermAudVid->nResult == CERR_SUCCESS)
				sprintf(strText, "关闭终端音频成功！终端ID:0x%X ", pAswCloseTermAudVid->dwTermID);
			else
				sprintf(strText, "关闭终端音频失败！终端ID:0x%X ，错误代码:%d", pAswCloseTermAudVid->dwTermID, pAswCloseTermAudVid->nResult);
			printf("%s \n", strText);
			break;
		}
        //应答获取终端音量级别
		case CB_Asw_GetAudLevel:
		{
			ASSERT(dwSize == sizeof(TSdkAswGetAudLevel));
			TSdkAswGetAudLevel * pAswGetAudLevel = (TSdkAswGetAudLevel*)pParam;
//			g_pMainWnd->m_nCapLevel = pAswGetAudLevel->Level.eCapLevel;
//			g_pMainWnd->m_nAmpLevel = pAswGetAudLevel->Level.eAmpLevel;
//			((CComboBox*)g_pMainWnd->GetDlgItem(IDC_CMB_CAP))->SetCurSel(g_pMainWnd->m_nCapLevel);
//			((CComboBox*)g_pMainWnd->GetDlgItem(IDC_CMB_AMP))->SetCurSel(g_pMainWnd->m_nAmpLevel);
			break;
		}
        //应答设置终端音量级别
		case CB_Asw_SetAudLevel:
		{
			ASSERT(dwSize == sizeof(TSdkAswSetAudLevel));
			TSdkAswSetAudLevel * pAswSetAudLevel = (TSdkAswSetAudLevel*)pParam;
			char strText[256];
			if(pAswSetAudLevel->nResult == CERR_SUCCESS)
				sprintf(strText, "设置终端音量成功！终端ID:0x%X ", pAswSetAudLevel->dwTermID);
			else
				sprintf(strText, "设置终端音量失败！终端ID:0x%X ，错误代码:%d", pAswSetAudLevel->dwTermID, pAswSetAudLevel->nResult);
			printf("%s \n", strText);
			break;
		}
        //应答设置终端喧哗报警配置
		case CB_Asw_SetDbAlmCfg:
		{
			ASSERT(dwSize == sizeof(TSdkAswSetDbAlmCfg));
			TSdkAswSetDbAlmCfg * pAswSetDbAlmCfg = (TSdkAswSetDbAlmCfg*)pParam;
			char strText[256];
			if(pAswSetDbAlmCfg->nResult == CERR_SUCCESS)
				sprintf(strText, "修改终端配置成功！终端ID:0x%X ", pAswSetDbAlmCfg->dwTermID);
			else
				sprintf(strText, "修改终端配置失败！终端ID:0x%X ，错误代码:%d", pAswSetDbAlmCfg->dwTermID, pAswSetDbAlmCfg->nResult);
			printf("%s \n", strText);
			break;
		}
        //应答打开终端对讲
		case CB_Asw_OpenTermTalk:
		{
			ASSERT(dwSize == sizeof(TSdkAswOpenTermTalk));
			TSdkAswOpenTermTalk * pAswOpenTermTalk = (TSdkAswOpenTermTalk*)pParam;
			char strText[256];
			if(pAswOpenTermTalk->nResult == CERR_SUCCESS)
				sprintf(strText, "打开终端对讲成功！终端ID:0x%X ", pAswOpenTermTalk->dwTermID);
			else
				sprintf(strText, "打开终端对讲失败！终端ID:0x%X ，错误代码:%d", pAswOpenTermTalk->dwTermID, pAswOpenTermTalk->nResult);
			printf("%s \n", strText);
			break;
		}
        //应答关闭终端对讲
		case CB_Asw_CloseTermTalk:
		{
			ASSERT(dwSize == sizeof(TSdkAswCloseTermTalk));
			TSdkAswCloseTermTalk * pAswCloseTermTalk = (TSdkAswCloseTermTalk*)pParam;
			char strText[256];
			if(pAswCloseTermTalk->nResult == CERR_SUCCESS)
				sprintf(strText, "关闭终端对讲成功！终端ID:0x%X ", pAswCloseTermTalk->dwTermID);
			else
				sprintf(strText, "关闭终端对讲失败！终端ID:0x%X ，错误代码:%d", pAswCloseTermTalk->dwTermID, pAswCloseTermTalk->nResult);
			printf("%s \n", strText);
			break;
		}
        //推送终端状态
		case CB_Post_TermState:
		{
			ASSERT(dwSize == sizeof(TSdkPostTermState));
			TSdkPostTermState * pPostTermState = (TSdkPostTermState*)pParam;
			
			int i;
			for(i=0; i<g_nTermCnt; i++)
			{
				if(g_TermList[i].dwTermID == pPostTermState->dwTermID)
				{
					g_TermState[i].eState = pPostTermState->eTermState;
					g_TermState[i].AlmInState = pPostTermState->AlmInState;
					g_TermState[i].AlmOutState = pPostTermState->AlmOutState;
					break;
				}
			}

			char strText[256];
			sprintf(strText, "终端ID:0x%X 终端状态:%s , IO报警 == 输入1:%s , 输入2:%s , 输出1:%s , 输出2:%s", 
                pPostTermState->dwTermID, GetStateText(pPostTermState->eTermState),
				AMSG(pPostTermState->AlmInState & 0x1), AMSG((pPostTermState->AlmInState >> 1) & 0x1),
				AMSG(pPostTermState->AlmOutState & 0x1), AMSG((pPostTermState->AlmOutState >> 1) & 0x1));
			printf("%s \n", strText);
            is_connect=1;printf("连接OK,is_connect:%d\n",is_connect);
			break;
		}
        //推送报警通知
		case CB_Post_AlmNotify:
		{
			ASSERT(dwSize == sizeof(TSdkPostAlmNotify));
			TSdkPostAlmNotify * pPostAlmNotify = (TSdkPostAlmNotify*)pParam;
			char strText[256];
			if((pPostAlmNotify->eAlmType & SDK_ALMTYPE_DB_ALARM) == SDK_ALMTYPE_DB_ALARM)
				sprintf(strText, "终端喧哗报警 !!!    终端ID:0x%X   通道号:%d", pPostAlmNotify->dwTermID, pPostAlmNotify->nChanNum);
			else
				sprintf(strText, "终端其他报警 !!!    终端ID:0x%X", pPostAlmNotify->dwTermID);
			printf("%s \n", strText);
			break;
		}
        //网络拾音器第一声道MP3音频
		case CB_Data_TermMp3L:
		{
			ASSERT(dwSize == sizeof(TSdkDataTermMp3L));
			TSdkDataTermMp3L * pDataTermMp3L = (TSdkDataTermMp3L*)pParam;
//			TRACE("== MP3音频 ID:%X ：大小 %d 字节\n", pDataTermMp3L->dwTermID,pDataTermMp3L->nDataSize);
//			if(g_pMp3File1 && pDataTermMp3L->dwTermID == g_TermList[g_nRecordTermIdx].dwTermID)
//				fwrite(pDataTermMp3L->pMp3Data, 1, pDataTermMp3L->nDataSize, g_pMp3File1);

			int i;
			for(i=0; i<g_nTermCnt; i++)
			{
				if(g_TermList[i].dwTermID == pDataTermMp3L->dwTermID)
				{
					if(g_TermState[i].pMp3File1)
						fwrite(pDataTermMp3L->pMp3Data, 1, pDataTermMp3L->nDataSize, g_TermState[i].pMp3File1);
					break;
				}
			}

			break;
		}
        //网络拾音器第二声道MP3音频
		case CB_Data_TermMp3R:
		{
			ASSERT(dwSize == sizeof(TSdkDataTermMp3R));
			TSdkDataTermMp3R * pDataTermMp3R = (TSdkDataTermMp3R*)pParam;
//			TRACE("== MP3音频 ID:%X ：大小 %d 字节\n", pDataTermMp3R->dwTermID,pDataTermMp3R->nDataSize);
//			if(g_pMp3File2 && pDataTermMp3R->dwTermID == g_TermList[g_nRecordTermIdx].dwTermID)
//				fwrite(pDataTermMp3R->pMp3Data, 1, pDataTermMp3R->nDataSize, g_pMp3File2);
			int i;
			for(i=0; i<g_nTermCnt; i++)
			{
				if(g_TermList[i].dwTermID == pDataTermMp3R->dwTermID)
				{
					if(g_TermState[i].pMp3File2)
						fwrite(pDataTermMp3R->pMp3Data, 1, pDataTermMp3R->nDataSize, g_TermState[i].pMp3File2);
					break;
				}
			}

			break;
		}
        //网络拾音器第一声道PCM音频(16K采样率16位)
		case CB_Data_TermPcmL:
		{
			ASSERT(dwSize == sizeof(TSdkDataTermPcmL));
			TSdkDataTermPcmL * pDataTermPcmL = (TSdkDataTermPcmL*)pParam;//输入的数据
			// printf("== Pcm音频L ID:%X ：大小 %d 字节,地址 0x%x \n", pDataTermPcmL->dwTermID,pDataTermPcmL->nDataSize,pDataTermPcmL->pPcmData);
			if(g_pPcmFileL && pDataTermPcmL->dwTermID == g_TermList[g_nRecordTermIdx].dwTermID){
				fwrite(pDataTermPcmL->pPcmData, 1, pDataTermPcmL->nDataSize, g_pPcmFileL);
			}
			g_nPcmTotalLenL += pDataTermPcmL->nDataSize;

#if COMMUNICATION_MODE == MQUEUE
			mqueue_send('l',pDataTermPcmL->pPcmData,pDataTermPcmL->nDataSize);
#elif COMMUNICATION_MODE == PIPE
			if(pipo_L_data_fd > 0){
				pipe_send(pipo_L_data_fd,pDataTermPcmL->pPcmData,pDataTermPcmL->nDataSize);
			}
#else

#endif
			break;
		}
        //网络拾音器第二声道PCM音频(16K采样率16位)
		case CB_Data_TermPcmR:
		{
			ASSERT(dwSize == sizeof(TSdkDataTermPcmR));
			TSdkDataTermPcmR * pDataTermPcmR = (TSdkDataTermPcmR*)pParam;
			// printf("== Pcm音频R ID:%X ：大小 %d 字节,地址 0x%x \n", pDataTermPcmR->dwTermID,pDataTermPcmR->nDataSize,pDataTermPcmR->pPcmData);
			if(g_pPcmFileR && pDataTermPcmR->dwTermID == g_TermList[g_nRecordTermIdx].dwTermID){
				fwrite(pDataTermPcmR->pPcmData, 1, pDataTermPcmR->nDataSize, g_pPcmFileR);
			}
			g_nPcmTotalLenR += pDataTermPcmR->nDataSize;

#if COMMUNICATION_MODE == MQUEUE
			mqueue_send('r',pDataTermPcmR->pPcmData,pDataTermPcmR->nDataSize);
#elif COMMUNICATION_MODE == PIPE
			if(pipo_R_data_fd > 0){
				pipe_send(pipo_R_data_fd,pDataTermPcmR->pPcmData,pDataTermPcmR->nDataSize);
			}
#else

#endif

			break;
		}
        //终端的音频，已经压缩过的，需要调用SDK播放接口才能播放
		case CB_Data_TermAudio:
		{
			ASSERT(dwSize == sizeof(TSdkDataTermAudio));
			TSdkDataTermAudio * pDataTermAudio = (TSdkDataTermAudio*)pParam;
//			TRACE("== 终端音频 ID:%X ：大小 %d 字节\n", pDataTermAudio->dwTermID,pDataTermAudio->nDataSize);
			TSDK_Player_AudVidAdd(1, TSDK_AUDIO, pDataTermAudio->pAudData, pDataTermAudio->nDataSize);
			break;
		}
        //电脑的音频，为PCM帧，8K采样率，16位/样
		case CB_Data_PcMicAudio:
		{
			ASSERT(dwSize == sizeof(TSdkDataPcMicAudio));
			TSdkDataPcMicAudio * pDataPcAudio = (TSdkDataPcMicAudio*)pParam;
//			TRACE("== 电脑麦克风音频：大小 %d 字节\n", pDataPcAudio->nDataSize);

			if(g_nTalkTermIdx != -1)
			{
				TSDK_Send_TalkAudio(g_TermList[g_nTalkTermIdx].dwTermID,
					pDataPcAudio->pPcmData, pDataPcAudio->nDataSize);
			}

			break;
		}
		//推送网络拾音器第一声道音量值
		case CB_Post_TermDbValL:
		{
			ASSERT(dwSize == sizeof(TSdkPostTermDbValL));
			TSdkPostTermDbValL * pPostTermDbValL = (TSdkPostTermDbValL*)pParam;
			// printf(">>>>>> nDbVal_L:%d \n", pPostTermDbValL->nDbVal);
			l_db = pPostTermDbValL->nDbVal;
			break;
		}
        //推送网络拾音器第二声道音量值
		case CB_Post_TermDbValR:
		{
			ASSERT(dwSize == sizeof(TSdkPostTermDbValR));
			TSdkPostTermDbValR * pPostTermDbValR = (TSdkPostTermDbValR*)pParam;
			// printf(">>>>>> nDbVal_R:%d \n", pPostTermDbValR->nDbVal);
			r_db = pPostTermDbValR->nDbVal;
			break;
		}

		default:
		{
			ASSERT(FALSE);
			break;
		}
	}

	return CERR_SUCCESS;
}